package ar.edu.unicen.pladema.ui.panel.options;

import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;

import ar.edu.unicen.pladema.main.SWTUtils;
import ar.edu.unicen.pladema.ui.mywidgets.OffsetPanel;
import ar.edu.unicen.pladema.ui.mywidgets.ZoomPanel;
import ar.edu.unicen.pladema.vc1.model.GraphicAttributes;
import ar.edu.unicen.pladema.vc1.practico.PanelOption;

public class POP2E2 extends PanelOption {

	private ZoomPanel zoomPanel;
	private OffsetPanel offsetPanel;

	public POP2E2(Composite parent, IPaintIt pi, GraphicAttributes ga) {
		super(parent, pi, ga);
	}

	@Override
	protected void createWidgetsImpl() {
		zoomPanel = new ZoomPanel(this);
		offsetPanel = new OffsetPanel(this);
	}

	@Override
	protected FormData layoutWidgets(FormData fd) {
		zoomPanel.setLayoutData(fd);
		offsetPanel.setLayoutData(SWTUtils.createBelowFormData(zoomPanel,5));
		return SWTUtils.createBelowFormData(offsetPanel,5);
	}

	@Override
	protected void loadGraphicData() {
		zoomPanel.setValue(graphicAttributes.get(GraphicAttributes.ZOOM));
		offsetPanel.setWidth(graphicAttributes.getInt(GraphicAttributes.OFFSET_X));
		offsetPanel.setHeight(graphicAttributes.getInt(GraphicAttributes.OFFSET_Y));
		this.pack();
	}

	@Override
	protected void saveGraphicData() {
		graphicAttributes.add(GraphicAttributes.ZOOM, zoomPanel.getValue());
		graphicAttributes.add(GraphicAttributes.OFFSET_X, offsetPanel.getWidth());
		graphicAttributes.add(GraphicAttributes.OFFSET_Y, offsetPanel.getHeight());
	}
}
